package com.cykj.faceledtv.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.net.Uri;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.cykj.faceledtv.R;

/**
 * glide
 *
 * @author jzh
 * @date 2018/12/13 11:10
 */
public class GlideUtils {
    public static void loadImage(Context context, String url, ImageView imageView) {
        RequestOptions options = new RequestOptions()
                .placeholder(R.drawable.placeholder)
                .error(R.drawable.error_img)
                .centerCrop();
        Glide.with(context).load(url).apply(options).into(imageView);
    }

    public static void loadImage(Context context, Bitmap bitmap, ImageView imageView) {
        RequestOptions options = new RequestOptions()
                .placeholder(R.drawable.placeholder)
                .error(R.drawable.error_img)
                .centerCrop();
        Glide.with(context).load(bitmap).apply(options).into(imageView);
    }

    public static void loadImage(Context context, Uri uri, ImageView imageView) {
        RequestOptions options = new RequestOptions()
                .placeholder(R.drawable.placeholder)
                .error(R.drawable.error_img)
                .centerCrop();
        Glide.with(context).load(uri).apply(options).into(imageView);
    }

    /**
     * 灰色底调的占位图和错误图
     */
    public static void loadImageWithOtherImg(Context context, Bitmap bitmap, ImageView imageView) {
        RequestOptions options = new RequestOptions()
                .placeholder(R.color.colorLoginNormal)
                .error(R.color.colorLoginNormal)
                .centerCrop();
        Glide.with(context).load(bitmap).apply(options).into(imageView);
    }

}
